home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / src / dicehelp / StripADoc.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  3KB  |  178 lines

  1. /*
  2.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  3.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  4.  *    DICE-LICENSE.TXT.
  5.  */
  6. /*
  7. **      $Id: StripADoc.c,v 30.0 1994/06/10 18:05:51 dice Exp $
  8. **
  9. **    Process full Commodore AutoDoc files into a reduced version they'll
  10. **    actually let us ship.
  11. **
  12. */
  13. #define D(x)    ;
  14.  
  15. /*
  16.  *  StripADoc output <pattern>
  17.  *
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. #define unless(x)       if(!(x))
  24.  
  25. #define    FF    12
  26.  
  27. char *SetSName(char *, char *);
  28. char *TailPath(char *path);
  29. char *strcpyc(char *d, char *s, char c);
  30.  
  31. main(xac, xav)
  32. int xac;
  33. char *xav[];
  34. {
  35.     short i;
  36.     FILE *fi;
  37.     FILE *fo;
  38.     int ac;
  39.     char **av;
  40.  
  41.     expand_args(xac, xav, &ac, &av);
  42.  
  43.         // !!! Add ? support
  44.     if (ac < 2) {
  45.     puts("StripAdoc appendfile <sourcepattern> <sourcepattern>");
  46.     puts(";Convert full AutoDocs into reduced format");
  47.     exit(1);
  48.     }
  49.     fo = fopen(av[1], "a");
  50.     if (!fo) {
  51.     printf("Error: Unable to open %s for append\n", av[1]);
  52.     exit(1);
  53.     }
  54.     for (i = 2; i < ac; ++i) {
  55.     char *file = av[i];
  56.     short len = strlen(file);
  57.  
  58.     fi = fopen(file, "r");
  59.     if (fi)
  60.     {
  61.         printf("Scanning DOC file: %s\n", file);
  62.         scandocfile(fi, fo, file);
  63.         fclose(fi);
  64.     } else
  65.     {
  66.         printf("Unable to read %s\n", file);
  67.     }
  68.     }
  69.     return(0);
  70. }
  71.  
  72.  
  73.  
  74.  
  75. #define    ST_AFTER_RESULT    0
  76. #define    ST_AFTER_FF    1
  77.  
  78. scandocfile(fi, fo, filename)
  79. FILE *fi;
  80. FILE *fo;
  81. char *filename;
  82. {
  83.     char buf[256];
  84.     int  state=ST_AFTER_FF;
  85.  
  86.     while (fgets(buf, 256, fi)) {
  87.     short len = strlen(buf) - 1;
  88.     char *bas = buf;
  89.  
  90.     buf[len] = 0;
  91.  
  92.     while( *bas ) {
  93.         switch( *bas ) {
  94.             case 'F':
  95.                 if( 0==strncmp(bas,"FUNCTION",8) )
  96.                     state = ST_AFTER_RESULT;
  97.                 break;
  98.             case 'I':
  99.                 if( 0==strncmp(bas,"INPUT",5) )
  100.                     state = ST_AFTER_RESULT;
  101.                 break;
  102.             case FF:
  103.                 state = ST_AFTER_FF;
  104.                 break;
  105.             default:
  106.         }
  107.         bas++;
  108.     }
  109.  
  110.     if( state )
  111.         fprintf(fo,"%s\n",buf);
  112.     }
  113.  
  114. }
  115.  
  116.  
  117. //      Like strcpy, but stops at the given character
  118. char *strcpyc(char *d, char *s, char c)
  119. {
  120.     char *base = d;
  121.  
  122.     while (*d = *s) {
  123.         if (*s == c) {
  124.             *d = 0;
  125.             break;
  126.             }
  127.     ++s;
  128.     ++d;
  129.     }
  130.     return(base);
  131. }
  132.  
  133.  
  134. /*
  135. **      Extract name from whitespace
  136. */
  137. char *
  138. SetSName(buf, ptr)
  139. char *buf, *ptr;
  140. {
  141.     while (*ptr == ' ' || *ptr == 9)
  142.     ++ptr;
  143.     while (*ptr && *ptr != '\n' && *ptr != ' ' && *ptr != 9 && *ptr != 12)
  144.     *buf++ = *ptr++;
  145.     *buf = 0;
  146.     return(ptr);
  147. }
  148.  
  149.  
  150. /*      0=not alpha
  151. **      1=alpha
  152. */
  153. IsAlphaNum(c)
  154. char c;
  155. {
  156.     if ((c >= 'a' && c <= 'z') ||
  157.     (c >= 'A' && c <= 'Z') ||
  158.     (c >= '0' && c <= '9') ||
  159.     (c == '_') || (c == '-') || (c == ',') || (c == '.') || (c == '(') || (c == ')')
  160.     )
  161.     return(1);
  162.     return(0);
  163. }
  164.  
  165.  
  166. /*
  167. **      Return filename portion of complete path
  168. */
  169. char *TailPath(char *path)
  170. {
  171. char *last;
  172.  
  173.     unless( last=strrchr(path,'/' ) )    // Return last slash...
  174.         unless( last=strrchr(path,':') ) // or if no slash, last :
  175.             return( path );             // or if neither, input string
  176.     return( last+1 );
  177. }
  178.